/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BotRidder;

import java.util.Random;

public class Bot {

    private int posx, posy;
    private boolean equip, brush, desp;
    private char dir;
    private int [][] cuadrante;
    private boolean coin;
       
    
    public Bot(){
        
        posx = 0;
        posy = 0;
        equip = false;
        dir = 'e';
        brush = false;
        desp = false;
        cuadrante = new int[8][8];
    
        for(int i=0; i<8;i++){
            
            for(int j=0; j<8; j++){
                
               cuadrante [i][j] = 0; 
            }
         this.ocupar(6, 2, 3);   
       }
        
        
    }
    public void move(){
        if(dir == 'n'){
            this.north();
            
        }else if(dir == 'o'){
            this.west();
            
        }else if(dir == 'e'){
            this.east();
            
        }else{
           this.south();
        }
   }
    public void back(){
        if(dir == 'n'){
            this.south();
            dir = 'n';
        }else if(dir == 'o'){
            this.east();
            dir = 'o';
        }else if(dir == 'e'){
            this.west();
            dir = 'e';
        }else{
            this.north();
            dir = 's';
        }
    }
    public void left(){
        if(dir == 'n'){
            dir = 'o';
        }else if(dir == 'o'){
            dir = 's';
        }else if(dir == 'e'){
            dir = 'n';
        }else{
           dir = 'e';
        }
    }
    public void right(){
        if(dir == 'n'){
            dir = 'e';
        }else if(dir == 'o'){
            dir = 'n';
        }else if(dir == 'e'){
            dir = 's';
        }else{
           dir = 'o';
        }
    }
    public void north(){
        int valor = cuadrante[(posx/30)][((posy-30)/30)];
        
        if ( valor <2 && posy>-1){
            
            posy = posy-30;
            dir = 'n';
        }else{
            dir = 'n';
        }
              
    }
    public void south(){
        int valor = cuadrante[(posx/30)][((posy+30)/30)];
        
        if ( valor<2 && posy<240){
            
            posy = posy+30;
            dir = 's';
        }else{
            dir = 's';
        }
    }
    public void west(){
        int valor = cuadrante[((posx-30)/30)][(posy/30)]; 
        if ( valor<2 && posx>-1){
            
            posx = posx-30;
            dir = 'o';
        }else{
            dir = 'o';
        }
        
    }
    public void east(){
        int valor = cuadrante[((posx+30)/30)][(posy/30)];
        if ( valor<2 && posx<240){
            
            posx = posx+30;
            dir = 'e';
        }else{
            dir = 'e';
        }
            
    }
    public void drop(){
        if(equip){
          if(this.seePaint()){
              this.set(4);
              equip = false;
          }else if (this.seeClear()){
              this.set(3);
              equip = false;
          } 
          
        }
    }
    public void take(){
        if(equip == false){
          if(this.see(3)){
              this.set(0);
          }else if(this.see(4)){
              this.set(1);
          }
              
        }
    }
    public boolean toss(){
        Random generator = new Random();
        int coina = generator.nextInt(2);
        if (coina == 0){
            return true;
        }else{
            return false;
        }
        
    }
    
    public boolean seePaint(){
        return this.see(1);
    }
    public boolean seeObstacle(){
        return this.see(2);
    }
    public boolean seeObject(){
        if(this.see(3) || this.see(4)){
            return true;
        }else{
            return false;
        }
    }
    public boolean seeClear(){
        return this.see(0);
    }
    
    public boolean see(int q){
        int val;
        if(dir == 'n'){
            val = cuadrante [posx/30][(posy-30)/30];
            if(val == q){
                return true;
            }else{
                return false;
            }
        }else if(dir == 'e'){
            val = cuadrante [(posx+30)/30][posy/30];
            if(val == q){
                return true;
            }else{
                return false;
            }
            
        }else if(dir == 'o'){
            val = cuadrante [(posx-30)/30][posy/30];
            if(val == q){
                return true;
            }else{
                return false;
            }
            
        }else{
           val = cuadrante [posx/30][(posy+30)/30];
            if(val == q){
                return true;
            }else{
                return false;
            } 
        }
        
        
    }
    public void set(int q){
        
        if(dir == 'n'){
            cuadrante [posx/30][(posy-30)/30] = q;
            
        }else if(dir == 'e'){
            cuadrante [(posx+30)/30][posy/30] = q;
            
        }else if(dir == 'o'){
            cuadrante [(posx-30)/30][posy/30] = q;
            
        }else{
           cuadrante [posx/30][(posy+30)/30] = q;
             
        }
        
        
    }
    public void paint(){
        brush = true;
    }
    public void nopaint(){
        brush = false;
        desp = false;
    }
    public void unpaint(){
        desp = true;
    }
    public int getX(){
        return posx;
    }
    public int getY(){
        return posy;
    }
    public char getDir(){
        return dir;
    }
    public boolean getEquip(){
        return equip;
    }
    public boolean getBrush(){
        return brush;
    }
    public boolean getDesp(){
        return desp;
    }
    public int ang1Inicio(){
        int p;
        if(dir == 'n'){
            p = 10;
            return p;
        }else if (dir == 'e'){
            p = 20;
            return p;
        }else if (dir == 'o'){
            p = 5;
            return p;
        }else{
            p = 10;
            return p;
        }    
    }
    public int ang1Final(){
        int o;
        if(dir == 'n'){
            o = 5;
            return o;
        }else if (dir == 'e'){
            o = 10;
            return o;
        }else if (dir == 'o'){
            o = 10;
            return o;
        }else{
            o = 20;
            return o;
        }    
    }
    public int ang2Inicio(){
        int p;
        if(dir == 'n'){
            p = 15;
            return p;
        }else if (dir == 'e'){
            p = 20;
            return p;
        }else if (dir == 'o'){
            p = 5;
            return p;
        }else{
            p = 15;
            return p;
        }    
    }
    public int ang2Final(){
        int o;
        if(dir == 'n'){
            o = 5;
            return o;
        }else if (dir == 'e'){
            o = 15;
            return o;
        }else if (dir == 'o'){
            o = 15;
            return o;
        }else{
            o = 20;
            return o;
        }
        
    }
    public void ocupar(int a, int b, int c){
        (cuadrante [a][b] ) = c;
    }
    public int verMatriz(int i, int j){
        return cuadrante [i][j]; 
       
    }
    public void reiniciar(){
        posx = 0;
        posy = 0;
        dir = 'e';
    }
}
